<?xml version="1.0" encoding="UTF-8"?>
<%! import rage.Geometry %>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
	<g:if test="${flash.message}">
           	<Placemark>
			<name>ERROR</name>
			<description>${flash.message}</description>
		</Placemark>
	</g:if>
	<g:else>
		<Style id="<g:rgbToBGR>${feedColor}</g:rgbToBGR>">
			<IconStyle>
				<color>ff<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<scale>1</scale>
				<Icon>
					<href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href>
 				</Icon>
			</IconStyle>
			<LineStyle>
				<color>7d<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<width>2.0</width>
			</LineStyle>
			<PolyStyle>
				<color>7d<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<colorMode>normal</colorMode>
				<fill>false</fill>
				<outline>true</outline>
			</PolyStyle>
			<BalloonStyle>
				<text>$[description]</text>
			</BalloonStyle>
		</Style>
		<g:each in="${feedInstance.placemarks}" status="i" var="placemarkInstance">
			<Placemark>
				<name><![CDATA[${placemarkInstance.name}]]></name>
				<description>
					<![CDATA[${placemarkInstance.description}]]>
				</description>
				<styleUrl>#<g:rgbToBGR>${feedColor}</g:rgbToBGR></styleUrl>
				<g:if test="${placemarkInstance.timestamp}">
					<TimeStamp>
						<when>${placemarkInstance.timestamp}</when>
					</TimeStamp>
				</g:if>
				<g:if test="${placemarkInstance.geometry == null || placemarkInstance.geometry.points == null}">
					<Snippet>
						No geolocation data available!
					</Snippet>
				</g:if>
				<g:elseif test="${placemarkInstance.geometry.points.size() == 1}">
					<Point>
						<coordinates>${placemarkInstance.geometry.points.get(0).getX()},${placemarkInstance.geometry.points.get(0).getY()},0</coordinates>
					</Point>
				</g:elseif>
				<g:elseif test="${placemarkInstance.geometry.points.size() > 1}">
					<MultiGeometry>
						<g:if test="${placemarkInstance.geometry.type == Geometry.Type.POINT}">
							<g:each in="${placemarkInstance.geometry.points}" status="j" var="pointInstance">
								<Point>
									<coordinates>${pointInstance.getX()},${pointInstance.getY()},0</coordinates>
								</Point>
							</g:each>
						</g:if>
						<g:elseif test="${placemarkInstance.geometry.type == Geometry.Type.POLYGON}">
							<Point>
								<coordinates>${placemarkInstance.geometry.points.get(0).getX()},${placemarkInstance.geometry.points.get(0).getY()},0</coordinates>
							</Point>
							<Polygon>
								<outerBoundaryIs>
									<LinearRing>
										<coordinates>
											<g:each in="${placemarkInstance.geometry.points}" status="j" var="pointInstance">
												${pointInstance.getX()},${pointInstance.getY()},0</g:each>
										</coordinates>
									</LinearRing>
								</outerBoundaryIs>
							</Polygon>
						</g:elseif>
					</MultiGeometry>
				</g:elseif>
				<g:else>
				</g:else>
			</Placemark>
		</g:each>
	</g:else>
	</Document>
</kml>